package com.xrz.sxm.aj.activity;

import android.app.ProgressDialog;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.lidroid.xutils.util.LogUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.xrz.sxm.aj.base.BaseAct;
import com.xrz.sxm.aj.entity.User;
import com.xrz.sxm.aj.utils.SharedPreferencesUtils;
import com.xrz.sxm.aj.utils.Utils;

public class About_YijianFankuiActivity extends BaseAct {

	@ViewInject(R.id.medit)
	private EditText medit;
	@Override
	protected int setView() {
		return R.layout.layout_about_yjfankui;
	}

	private ProgressDialog progressBarDialog;


	@Override
	protected void init() {
		progressBarDialog = new ProgressDialog(this);
		progressBarDialog.setMessage("加载中...");
	}
   
	public void send(View v){
		final String content = medit.getText().toString().trim();
		if(TextUtils.isEmpty(content)){
			Toast.makeText(this,"请输入反馈内容", Toast.LENGTH_SHORT).show();
			return;
		}
		progressBarDialog.show();
		new Thread(){
			@Override
			public void run() {
				super.run();
				String host = "smtp.163.com";
				String address = "henanailin@163.com";
				String from = "henanailin@163.com";
				String password = "aaa000000";// 密码
				String port = "25";
				try{
					User user = (User) SharedPreferencesUtils.readObject(About_YijianFankuiActivity.this,"user");
					Utils.SendEmail(host, address, from, password, address, port, "反馈信息", "用户信息："+user.toString()+"\n\n\t"+"反馈信息："+content);
					handler.sendEmptyMessage(1);
				}catch (Exception e){
					LogUtils.e(e.toString());
					handler.sendEmptyMessage(2);
				}

			}
		}.start();
	}

	private Handler handler = new Handler(){
		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			if(msg.what == 1){
				progressBarDialog.dismiss();
				toastLong("感谢您的反馈！");
				finish();
			}else if(msg.what == 2){
				progressBarDialog.dismiss();
				toastLong("反馈发送失败，请稍后再试！");
			}
		}
	};
	
	@Override
	protected String setTopTitle() {
		return null;
	}

	@Override
	protected boolean topHide() {
		return true;
	}

}
